package com.neuedu.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.neuedu.mapper.RentMapper;
import com.neuedu.po.AssiantPO;
import com.neuedu.po.ImagePO;
import com.neuedu.po.RentPO;
import com.neuedu.po.RentalAssiantPO;
import com.neuedu.po.RentalImagePO;
import com.neuedu.po.ViewRentPO;
import com.neuedu.service.RentService;
import com.neuedu.util.PageUtil;
import com.neuedu.vo.RentListSearchVO;
import com.neuedu.vo.RentListVO;

@Service
public class RentServiceImpl implements RentService {
	
	@Autowired
	private RentMapper mapper;

	@Override
	public List<RentListVO> getRentList(RentListSearchVO vo) {
		// TODO Auto-generated method stub
		Integer start = PageUtil.getStartIndex(vo.getPagenum(), vo.getLength());
		vo.setStart(start);
		return mapper.getRentList(vo);
	}
	
	@Override
	public Long getRentListCount(RentListSearchVO vo) {
		// TODO Auto-generated method stub
		return mapper.getRentListCount(vo);
	}
	
	@Override
	@Transactional
	public void insertNewRentalInfo(RentPO po, List<String> photo1, List<String> photo2, List<Integer> asslist) {
		mapper.insertRetal(po);
		int retid = po.getRetid();
		for(Integer i : asslist) {
			RentalAssiantPO x = new RentalAssiantPO();
			x.setRetid(retid);
			x.setAssid(i);
			mapper.insertRetalAssisant(x);
		}
		for(String s : photo1) {
			RentalImagePO x = new RentalImagePO();
			x.setRetid(retid);
			x.setPurl(s);
			x.setPtype(1);
			mapper.insertRetalPhoto(x);
		}
		for(String s : photo2) {
			RentalImagePO x = new RentalImagePO();
			x.setRetid(retid);
			x.setPurl(s);
			x.setPtype(2);
			mapper.insertRetalPhoto(x);
		}
	}

	@Override
	public ViewRentPO getRentViewById(Integer rentid) {
		// TODO Auto-generated method stub
		return mapper.getRentViewById(rentid);
	}

	@Override
	public List<AssiantPO> getRentAssisantById(Integer rentid) {
		// TODO Auto-generated method stub
		return mapper.getRentAssisantById(rentid);
	}

	@Override
	public List<ImagePO> getRentPhotoById(Integer rentid) {
		// TODO Auto-generated method stub
		return mapper.getRentPhotoById(rentid);
	}
}
